﻿using System;
using Avalonia.Controls;
using FluentAvalonia.UI.Controls;
using iOSClub.WikiApp.Pages;
using iOSClub.WikiApp.TextPages;
using iOSClub.WikiApp.ViewModels;
using WikiApp.Lib;

namespace iOSClub.WikiApp.Views;

public class NavigationPageFactory : INavigationPageFactory
{
    public Control GetPage(Type srcType)
    {
        throw new Exception();
    }

    public Control GetPageFromObject(object target)
    {
        return target switch
        {
            PageItem item => item.ContentType switch
            {
                "markdown" => new MarkdownPage() { DataContext = item },
                "list" => new TextBlock(),
                "html" => new HtmlPage() { DataContext = item },
                _ => throw new Exception()
            },
            string s => s switch
            {
                "Setting" => new SettingPage() { DataContext = new SettingViewModel() },
                "Help" => new HelpPage(),
                "Site" => new SitePage("https://wiki.xauat.site"),
                _ => new SitePage(s)
            },
            _ => throw new Exception()
        };
    }
}